package com.phpxiu.app.view.dialog;


import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.phpxiu.app.api.OnRoomPayListener;
import com.phpxiu.app.kkylive.R;

/**
 * Created by 吴金洲 on 2016/10/18
 */
public class RoomCoverDialog extends Dialog implements View.OnClickListener {
    private Button cancelBtn,continueBtn;
    private TextView msgView;
    private OnRoomPayListener mListener;
    private boolean isRecharge=false;
    private int rate=0;
    private String msg="";
    public RoomCoverDialog(Context context,int r) {
        super(context, R.style.interactiveDialog);
        rate=r;
        init(context);
    }

    final private void init(Context context){
        setContentView(R.layout.room_cover_dialog);
        cancelBtn=(Button)findViewById(R.id.dialog_cancel);
        cancelBtn.setOnClickListener(this);
        continueBtn=(Button)findViewById(R.id.dialog_ok);
        continueBtn.setOnClickListener(this);
        msgView=(TextView)findViewById(R.id.dialog_description);
        msg=String.format(context.getString(R.string.ui_pay_info_desc_1),rate+"");
    }

    public void show(boolean recharge) {
        isRecharge=recharge;
        if(isRecharge){
            msgView.setText(getContext().getString(R.string.ui_pay_info_desc_2));
            continueBtn.setText(getContext().getString(R.string.ui_recharge));
        }else {
            msgView.setText(msg);
            continueBtn.setText(getContext().getString(R.string.ui_pay));
        }
        super.show();
    }

    public void setOnRoomPayListener(OnRoomPayListener listener){
        mListener=listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.dialog_cancel:
                dismiss();
                if(mListener!=null){
                    mListener.onRoomPayCancel();
                }
                break;
            case R.id.dialog_ok:
                if(mListener!=null){
                    mListener.onRoomPay(isRecharge);
                }
                break;
        }
    }

    /**
     * 防止网络不佳的情况，点击多次付费
     * @param enable
     */
    public void enablePay(boolean enable){
        if(continueBtn!=null){
            continueBtn.setEnabled(enable);
        }
    }
}
